using UnityEngine;
using UnityEngine.UI;
using Voodoo.Sauce.Core;
using Voodoo.Sauce.Internal.Extension;

namespace Voodoo.Sauce.Debugger
{
	public class LegacyABTestsDebugScreen : Screen, IConditionalScreen
	{
		private const string NO_COHORT = "NO_COHORT";

		[SerializeField]
		private Text currentCohortText;

		[SerializeField]
		private Text restartGameText;

		[SerializeField]
		private Text cohortSizeText;

		public bool CanDisplay => !VoodooSettings.Load().UseRemoteConfig;

		private void Awake()
		{
			restartGameText.enabled = false;
			VoodooSettings voodooSettings = VoodooSettings.Load();
			cohortSizeText.text = $"{voodooSettings.GeUsersPercentPerCohort() * 100f}%";
			SetUpCohortButtons(voodooSettings);
		}

		private void OnEnable()
		{
		}

		private void SetUpCohortButtons(VoodooSettings settings)
		{
			CreateCohortButton("NO_COHORT");
			string[] runningABTests = settings.GetRunningABTests();
			foreach (string abTestName in runningABTests)
			{
				CreateCohortButton(abTestName);
			}
		}

		private void CreateCohortButton(string abTestName)
		{
			CohortButton cohortButton = WidgetUtility.InstanceOf<CohortButton>(base.Parent);
			cohortButton.SetOnClickListener(delegate
			{
				SetAbTest(abTestName);
			});
			cohortButton.SetTitleText(abTestName);
		}

		private void SetAbTest(string abTestName)
		{

			currentCohortText.text = abTestName;
			restartGameText.enabled = true;
		}
	}
}
